﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.FTradeModel
{
    public partial class GetPageFTradeSaleTypeConfigView : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "FTradeReceivablesAdd";
            }
        }
        /// <summary>
        /// 不用权限
        /// </summary>
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.none };
            }
        }
        /// <summary>
        /// 是否能延期操作
        /// </summary>
        protected bool CanSuspend
        {
            get
            {
                return GetRequestValue<bool>("CanSuspend", false);
            }
        }
        /// <summary>
        /// 获取当前要使用的销售类型
        /// </summary>
        protected string XiaoShouLeiXing
        {
            get
            {
                return obj.XiaoShouLeiXing;
            }
        }

        protected int FTradeSalesId
        {
            get
            {
                return GetRequestValue<int>("FTradeSalesId", 0);
            }
        }
        /// <summary>
        /// 是否显示缓期操作BTN
        /// </summary>
        protected bool ShowSuspendBtn
        {
            get
            {
                if (!FTradeSaleTypeConfigController.CanSuspendedMark(XiaoShouLeiXing))
                    return false;

                return GetRequestValue<int>("showsuspendbtn", 0) == 1;
            }
        }
        /// <summary>
        /// 根据已冲金额判断 如果大于0 则不能进行缓期操作。需人工调帐才能操作
        /// </summary>
        /// <param name="YiChongJinE"></param>
        /// <returns></returns>
        protected string GetCanSuspend(object FTradeAgeId,object YiChongJinE)
        {
            decimal _YiChongJinE = Convert.ToDecimal(YiChongJinE);

            if (ShowSuspendBtn)
            {
                if (_YiChongJinE > 0)
                {
                    return "<a href=\"javascript:alert('已冲帐过,请先手工进行调帐,再进行缓期操作')\" >不能缓期</a>";
                }
                else
                { 
                    return "<a  href=\"FTradeModel/FTradeAgeDetaiSuspendAdd.aspx?FTradeAgeId="+FTradeAgeId.ToString()+"\" style=\"color:red; font-weight:bold;\" target=\"dialog\" title=\"缓期操作\" rel=\"FTradeUpKeepAdd\" width=\"500\" height=\"350\" mask=\"true\">缓期</a>";
                }
            }
            return "<a href=\"javascript:alert('[" + XiaoShouLeiXing + "不支持缓期]')\">不能缓期</a>";
        }

        private FTradeSalesTypeInfo _objFx = null;

        protected FTradeSalesTypeInfo obj
        {
            get
            {
                if (_objFx == null)
                    _objFx = FTradeSalesTypeController.GetByFTradeSalesId(FTradeSalesId);
                return _objFx; 
            }
        }




        protected string getShowText(object SuspendedMark)
        {
            return Convert.ToInt32(SuspendedMark)>0?"<b>已缓期</b>":"";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            List<FTradeAgeDetailInfo> list = FTradeAgeDetailController.GetAllByFTradeSalesId(FTradeSalesId).Where(x => x.State == "正常" || x.State == "已冲帐").ToList();

            rpView.DataSource = list;
            rpView.DataBind();
        }

        protected string GetStateStr(object _State,object _DaoQiRi,object _JinE,object _YiChongJinE)
        {
            string state = _State.ToString();
            DateTime daoqiri = Convert.ToDateTime(_DaoQiRi);
            decimal shengYiJinE = Convert.ToDecimal(_JinE) - Convert.ToDecimal(_YiChongJinE);//未冲金额

            if (state == "正常")
            {

                if (daoqiri < DateTime.Now)
                {
                    return shengYiJinE > 0 ? "<b style='color:red;'>未充完,已到期</b>" : "<b style='color:red;'>已到期</b>";
                }
                else
                    return "<b  style='color:green;'>未到期</b>";
            }

            return state.Replace("冲", "充");
        }
    }
}